// LoggerConfig.h: interface for the LoggerConfig class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_LOGGERCONFIG_H__CB4D0B95_1473_41BD_9180_F51CA5F7B6F3__INCLUDED_)
#define AFX_LOGGERCONFIG_H__CB4D0B95_1473_41BD_9180_F51CA5F7B6F3__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <string>
//#include "StreamWrapper.h"
#include "socketstream.h"
#include <fstream>

class AppEventStream;

using namespace std;
typedef basic_ostream<char> output_stream;

class nullstream : public output_stream
{
public:
    struct nullbuf: std::streambuf 
	{ 
      int overflow(int c) { return traits_type::not_eof(c); } 
    } m_sbuf; 

    nullstream(): output_stream(&m_sbuf) {}
};


/************************************************************************/
/* this class is used for config the CLogger                            */
/************************************************************************/

class LoggerConfig  
{
public:
	LoggerConfig();
	~LoggerConfig();
	
	enum{OPERATION_LOCAL = 0, OPREATION_REMOTE, OPERATION_NONE, OPERATION_APPEVENT};
	enum{blocking = 0, unblocking};

public:
	//function members
	output_stream& ConfigStream(); //for constructor of stream in Logger
	void OnError(output_stream& outstream);//when error occurs, this function is called
	
	//return the working type of Logger: Socket stream or File stream, etc.
	inline int type()
	{
		return m_nOpType;
	}
	
	//return the Event used for synchronize the access Operation of stream
	//it's based on the config file
	HANDLE CreateStreamOpEvent();

	inline int mode()
	{
		return m_nOpMode;
	}

	inline DWORD timeout()
	{
		return m_blockingTimeout;
	}

	inline int buffersize()
	{
		return m_unblockingBufferSize;
	}

	inline int stringbuffermaxsize()//  [12/30/2011 pseudonym]
	{
		return m_nStringBuffserMaxSize;
	}
	DWORD GetCurrentProcessId();

protected:	
	//data member
	static const string Profile_File_Name;
	static const string File_Op_Event_Name;
	string m_sModulePath;// the path of module

	int m_nOpType;//Socket, file, or others
	int m_nOpMode;//blocking or unblocking
	int m_nStringBuffserMaxSize;//  [12/30/2011 pseudonym]

	struct _Server
	{
		string server_;
		int port_;
	}Server;

	string m_sLocallFile;//file name for local

	DWORD m_blockingTimeout;
	int m_unblockingBufferSize;

	TCPClientStream* m_pTcpStream;
	ofstream* m_pfStream;
	bool m_bGlobalFileEvent; // whether use the global file op event

	nullstream* m_pnullStream;
	AppEventStream* m_pWindowsEventStream;
};
/************************************************************************/
/* shared memory data type define                                       */
/************************************************************************/

typedef struct  
{
	DWORD filecount_;
	char filespath_[25600];
}struFilesPath;


/************************************************************************/
/* memory mapping class                                                 */
/*  [12/14/2012 Pseudonym]                                              */
/************************************************************************/
class CSharedMemory
{
public:
	CSharedMemory();
	~CSharedMemory();
	enum{BUF_SIZE = 25604};
public:
	void* GetMemoryAddress();
protected:
	void InitSharedMemory();
protected:
	HANDLE m_hMapFile;
	LPVOID m_pMemoryAddress;
private:
};


#endif // !defined(AFX_LOGGERCONFIG_H__CB4D0B95_1473_41BD_9180_F51CA5F7B6F3__INCLUDED_)
